package com.niit.project.entity;

//页码的实体类,将来用于分页显示
public class Page {
    private Integer pageIndex;      //当前页码
    private Integer pageSize;       //一页显示的行数,我们使用列表展示的商品信息,一行就是一个商品,所以pageSize就表示一行展示几个商品
    private Integer totalCounts;    //商品的总数
    private Integer totalPages;     //总页码,要通过总商品数除以每一页的商品数算出来
    private Integer startRows;      //起始行

    //
    public Page(Integer pageIndex) {
        this(pageIndex,5);
    }

    public Page(Integer pageIndex, Integer pageSize) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.setStartRows((pageIndex - 1)*pageSize);

    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    //将当前页设置为pageIndex
    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalCounts() {
        return totalCounts;
    }


    public void setTotalCounts(Integer totalCounts) {
        this.totalCounts = totalCounts;
//        设置总页数,下面用到了三目运算符,用总商品数对一页所表示的商品数求余,如果能整除,则将结果设置为总页码,如果不能整除,说明存在一页不满的情况,将结果加一,得到总页码
        setTotalPages(this.totalCounts % this.pageSize == 0 ? this.totalCounts/ this.pageSize :this.totalCounts / this.pageSize +1);

    }

    public Integer getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(Integer totalPages) {
        this.totalPages = totalPages;
    }

    public Integer getStartRows() {
        return startRows;
    }

    public void setStartRows(Integer startRows) {
        this.startRows = startRows;
    }
}
